package com.controller;

import com.pojo.Result;
import com.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * oss对象存储接口
 * @author lifeng
 * @create 2022-11-22 15:55
 */
//跨域
@CrossOrigin
@RestController
@RequestMapping("/oss/fileoss")
public class OssController {

    @Autowired
    private OssService ossService;

    @PostMapping
    public Result uploadOssFile(MultipartFile file){
        System.out.println("...................................");
        //获取上传文件 MultipartFile
        Result result = new Result();
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
//        if (url != ""){
            result.setCode(200);
            result.setMsg("上传成功");
            result.setData(url);
            System.out.println("上传成功，文件路径为：" + url);
//        }else {
//            result.setCode(500);
//            result.setMsg("上传失败");
//        }
        return result;
    }

}
